<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    class Person {
      constructor(name) {
        this.name = name
      }
    }
    class Dog {
      constructor(name) {
        this.name = name
      }
    }
    const p1 = new Person('孙悟空')
    const p2 = new Dog('旺财')
    /*
      多态：
       - js不会检查函数的类型，任何数据都可以作为参数传递
       - 狗可用sayHello,人也可以用
       - 多态为编程提供了灵活性
    */
    function sayHello(obj) {
      console.log('hello', obj.name)
    }
    sayHello(p1)
    sayHello(p2)
  </script>
</body>
</html>